package com.sfeir.server.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.googlecode.objectify.ObjectifyService;
import com.sfeir.server.dao.LevelDao;
import com.sfeir.shared.Level;
import com.sfeir.shared.Score;

/**
 * This listener will allow to initialize database when the application will
 * starts
 * 
 * @author Oussama Zoghlami
 * 
 */
public class DatabaseInitializerListener implements ServletContextListener {

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		
	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		registerObjectifyEntities();
		new LevelDao().initializeLevelData();
	}

	/**
	 * Method allowing to register Objectify Entities
	 */
	private void registerObjectifyEntities() {
		ObjectifyService.register(Level.class);
		ObjectifyService.register(Score.class);
	}

}
